import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_first_one/components/story_card_list.dart';
import 'package:flutter_first_one/api/story.dart';

class MorePage extends StatefulWidget {
  const MorePage({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _MorePageState createState() => _MorePageState();
}

class _MorePageState extends State<MorePage> {
  List<dynamic> storyType = [
    {'name': '热门AI故事', 'key': 'forwardNum', 'value': 'desc', 'dataType': 2},
    {'name': '重磅新品', 'key': 'id', 'value': 'desc', 'dataType': 2},
    {'name': '精品推荐', 'key': 'collectNum', 'value': 'desc', 'dataType': 2},
    {'name': '剧集故事', 'key': 'forwardNum', 'value': 'desc', 'dataType': 1}
  ];

  Map<String, dynamic> param = {
    'pageSize': 10,
    'dataType': 0,
    'sort': [
      {
        'key': '',
        'value': '',
      }
    ]
  };

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    // 获取页面传值
    print(Get.arguments);
    Map<String, dynamic> storyItem =
        storyType.firstWhere((v) => v['name'] == Get.arguments['key']);
    param['dataType'] = storyItem['dataType'];
    param['sort'] = [
      {'key': storyItem['key'], 'value': 'desc'}
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('儿时故事'),
      ),
      body: StoryCardList(requestApi: StoryApi.storyInfo, params: param),
    );
  }
}
